﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .topPanel .search .input-group .form-control {
        padding: 4px 5px !important;
        height: 22px !important;
        margin: 0 10px !important;
        width: 80%;
    }
    .zdyPanel {
        height: 50px;
        line-height: 50px;
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        height: 50px;
        line-height: 50px;
        padding: 0px;
        width: 100px;
        margin: 0px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        width: 100%;
        margin: 0px;
        padding: 0px;
        float: left;
    }

    .zdyContentPanel {
        width: 100%;
        margin: 5px 0px 0px 0px;
        padding: 0px;
        float: left;
    }

    .zdyFont {
        padding-left: 5px;
        color: #ff6a00;
    }
</style>
<script type="text/javascript">
    var resultData;
    $(function () {  
        InitAuthorize();
        getItemList();
        gridList();               
    });

    function InitAuthorize() {
        $.ajax({
            url: "/MyTask/MySalesReport/GetBottonAuth?keyValue=" + window.frameElement.id.replace("iframe",""),
            dataType: "json",
            async: false,
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    data[i].F_FullName
                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {

            }
        });
    }

    var selectPage = -1;
    function getItemList() {
        $.ajax({
            url: "/MyTask/MySalesReport/GetItemListJson",
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                
            }
        });
    }

    function dateFtt(fmt, date) { //author: meizz   
        var o = {
            "M+": date.getMonth() + 1,                 //月份   
            "d+": date.getDate(),                    //日   
            "h+": date.getHours(),                   //小时   
            "m+": date.getMinutes(),                 //分   
            "s+": date.getSeconds(),                 //秒   
            "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
            "S": date.getMilliseconds()             //毫秒   
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    } 

    function gridList() {
        var $gridList = $("#gridList"); 
        var queryJson = {};
        $gridList.dataGrid({
            url: "/MyTask/MySalesReport/GetGridList",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 400,
            colModel: [
                { label: '客户名称', name: 'F_ClientName', align: 'left'},
                { label: '活动名称', name: 'F_ActivityName', align: 'left' },
                {
                    label: '活动城市', name: 'F_CityId', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.citys.length; i++) {
                            if (resultData.citys[i]["F_ItemCode"] == rowObject["F_CityId"]) {
                                return resultData.citys[i]["F_ItemName"];
                            }
                        }
                    }
                },
                {
                    label: '活动进场时间', name: 'F_InStartTime', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '活动开始时间', name: 'F_StartTime', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '活动结束时间', name: 'F_EndTime', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '所属行业', name: 'F_ActivityIndustry', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.sshy.length; i++) {
                            if (resultData.sshy[i]["F_ItemCode"] == rowObject["F_ActivityIndustry"]) {
                                return resultData.sshy[i]["F_ItemName"];
                            }
                        }
                    }
                },
                {
                    label: '活动类型', name: 'F_ActivityType', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.activityType.length; i++) {
                            if (resultData.activityType[i]["F_ItemCode"] == rowObject["F_ActivityType"]) {
                                return resultData.activityType[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '预算金额', name: 'F_BudgetCash', align: 'left' },
                {
                    label: '活动阶段', name: 'F_ActivityStep', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.hdjd.length; i++) {
                            if (resultData.hdjd[i]["F_ItemCode"] == rowObject["F_ActivityStep"]) {
                                return resultData.hdjd[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '品牌', name: 'F_Brand', align: 'left' },
                {
                    label: '场地类型', name: 'F_SiteType', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.SiteType.length; i++) {
                            if (resultData.SiteType[i]["F_ItemCode"] == rowObject["F_SiteType"]) {
                                return resultData.SiteType[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '场地大小', name: 'F_SiteSize', align: 'left' },
                { label: '预计人数', name: 'F_PeopleNum', align: 'left' },
                {
                    label: '配套设施', name: 'F_Companions', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var strHtml = "";
                        for (var i = 0; i < resultData.SiteSupportingFacilities.length; i++) {
                            for (var j = 0; j < rowObject["F_Companions"].split(',').length; j++) {
                                if (j == rowObject["F_Companions"].split(',').length - 1) {
                                    if (resultData.SiteSupportingFacilities[i]["F_ItemCode"] == rowObject["F_Companions"].split(',')[j]) {
                                        strHtml += resultData.SiteSupportingFacilities[i]["F_ItemName"];
                                    }
                                } else {
                                    if (resultData.SiteSupportingFacilities[i]["F_ItemCode"] == rowObject["F_Companions"].split(',')[j]) {
                                        strHtml += resultData.SiteSupportingFacilities[i]["F_ItemName"] + ",";
                                    }
                                }                                
                            }
                        }
                        return strHtml;
                    }
                },
                { label: '创建时间', name: 'F_CreatorTime', align: 'left' },                
                { label: '', name: 'F_Id', hidden: true },
                { label: '', name: 'F_ClientId', hidden: true },
                {
                    label: '操作', name: '', align: 'left', width: 340, formatter: function (cellvalue, options, rowObject) {
                        return "<ul class=\"zdyUL\" style=\"white-space:nowrap;\"><li><a id=\"btnEdit\" name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_edit(this)\"><i class=\"fa fa-pencil-square-o\"></i>修改跟踪记录</a></li><li><a id=\"btnDelete\" name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_delete(this)\"><i class=\"fa fa-trash-o\"></i>删除跟踪记录</a></li><li><a id=\"btnDetail\" name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_detail(this)\"><i class=\"fa fa-search-plus\"></i>查看跟踪记录</a></li></ul>";
                    }
                }

            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_ClientId',
            ondblClickRow: function (rowid, iRow, iCol, e) {                
                reloadGridListRecord();
                selectPage = rowid;
            },
            loadComplete: function () {
                gridListRecord(0);                
            }            
        });    
    }

    function btn_detail(obj) {
        $.modalOpen({
            id: "ClientTrackingDetail",
            title: "详情-跟踪记录",
            url: "/MyTask/MySalesReport/Details?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            btn: null,
        });
    }

    function btn_add() {
        $.modalOpen({
            id: "ClientTracking",
            title: "新建-跟踪记录",
            url: "/MyTask/MySalesReport/Form",
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_edit(obj) {
        $.modalOpen({
            id: "ClientTrackingEdit",
            title: "编辑-跟踪记录",
            url: "/MyTask/MySalesReport/Form?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        }); 
    }

    function btn_delete(obj) {
        $.deleteForm({
            url: "/MyTask/MySalesReport/Delete",
            param: { keyValue: obj.name },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

    function btn_addVisit() {
        var rowobj = $("#gridList").jqGridRowValue();
        var F_ClientId;
        if (selectPage == -1) {
            F_ClientId = rowobj[0].F_ClientId;
        } else {
            F_ClientId = rowobj.F_ClientId;
        }
        $.modalOpen({
            id: "ClientTrackingVisit",
            title: "新建-客户拜访记录",
            url: "/MyTask/MySalesReport/Visit?F_ClientId=" + F_ClientId,
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function reloadGridListRecord() {
        var rowobj = $("#gridList").jqGridRowValue();
        var queryJson = {
            F_ClientId: rowobj == undefined ? "" : rowobj["F_ClientId"]
        };
        var $gridListRecord = $("#gridListRecord"); 
        $gridListRecord.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function gridListRecord(pageindex) {
        var $gridListRecord = $("#gridListRecord"); 
        var rowobj = $("#gridList").jqGridRowValue()[pageindex];
        var queryJson = {
            F_ClientId: rowobj == undefined ? "" : rowobj["F_ClientId"]
        };
        $gridListRecord.dataGrid({
            url: "/MyTask/MySalesReport/GetGridDetailList",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 200,
            colModel: [
                { label: '客户名称', name: 'F_ClientId', align: 'left' },
                { label: '对接人', name: 'F_DockingName', align: 'left' },
                { label: '手机号码', name: 'F_Phone', align: 'left' },
                {
                    label: '公司职位', name: 'F_PositionId', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.gszw.length; i++) {
                            if (resultData.gszw[i]["F_ItemCode"] == rowObject["F_PositionId"]) {
                                return resultData.gszw[i]["F_ItemName"];
                            }
                        }
                    }
                },                
                { label: '目标', name: 'F_Target', align: 'left' },               
                { label: '行动计划', name: 'F_Action', align: 'left' },                
                {
                    label: '行动日期', name: 'F_ActionDate', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return dateFtt("yyyy-MM-dd", new Date(cellvalue));
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: '工作进度', name: 'F_Progress', align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.hdjd.length; i++) {
                            if (resultData.hdjd[i]["F_ItemCode"] == rowObject["F_Progress"]) {
                                return resultData.hdjd[i]["F_ItemName"];
                            }
                        }
                    }
                },
                { label: '指标备注', name: 'F_IndexRemark', align: 'left' },
                { label: '创建时间', name: 'F_CreatorTime', align: 'left' },
                { label: '', name: 'F_Id', hidden: true },
                {
                    label: '操作', name: '', align: 'left', width: 340, formatter: function (cellvalue, options, rowObject) {
                        return "<ul class=\"zdyUL\" style=\"white-space:nowrap;\"><li><a id=\"btnEditVisit\" name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_editVisit(this)\"><i class=\"fa fa-pencil-square-o\"></i>修改拜访记录</a></li><li><a id=\"btnDeleteVisit\"  name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_deleteVisit(this)\"><i class=\"fa fa-trash-o\"></i>删除拜访记录</a></li><li><a id=\"btnDetailVisit\"  name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_detailVisit(this)\"><i class=\"fa fa-search-plus\"></i>查看拜访记录</a></li></ul>";
                    }
                }
            ],
            pager: "#gridPagerRecord",
            viewrecords: true,            
        });         
    }

    function btn_detailVisit(obj) {  
        $.modalOpen({
            id: "ClientTrackingVisitDetail",
            title: "查看-客户拜访记录",
            url: "/MyTask/MySalesReport/VisitDetails?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            btn: null,
        });   
    }

    function btn_editVisit(obj) {
        $.modalOpen({
            id: "ClientTrackingVisitDetail",
            title: "编辑-客户拜访记录",
            url: "/MyTask/MySalesReport/VisitForm?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_deleteVisit(obj) {
        $.deleteForm({
            url: "/MyTask/MySalesReport/DeleteForm",
            param: { keyValue: obj.name },
            success: function () {
                $.currentWindow().$("#gridListRecord").trigger("reloadGrid");
            }
        })
    }
</script>
<div class="zdyContentPanel" style="height:25px;line-height:25px;background-color:#eee;border:1px solid #ddd;margin-bottom:2px;">
    <span class="zdyFont">操作说明：上下表格行数据联动，请双击！</span>
</div>
<div class="zdyPanel">
    <div class="zdyTool">        
        <div class="zdyBar" style="float:right;white-space:nowrap;width:180px;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            <div class="btn-group">
                <a id="add" class="btn btn-primary dropdown-text" authorize="yes" onclick="btn_add()"><i class="fa fa-eraser"></i>新建跟踪记录</a>
            </div>
        </div>                
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<div class="zdyContentPanel">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#visitRecord" data-toggle="tab">拜访记录表</a></li>       
    </ul>
    <div class="tab-content">
        <div class="tab-pane fade in active" id="visitRecord">
            <div class="zdyPanel" style="margin-top:3px;">
                <div class="zdyTool">                    
                    <div class="zdyBar" style="float:right;white-space:nowrap;width:140px;">                        
                        <div class="btn-group">
                            <a id="addVisit" class="btn btn-primary dropdown-text" authorize="yes" onclick="btn_addVisit()"><i class="fa fa-eraser"></i>新建拜访记录</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="zdyGirdPanel">
                <table id="gridListRecord"></table>
                <div id="gridPagerRecord"></div>
            </div>
        </div>
        @*<div id="needRecord" class="tab-pane fade in">
            <div class="zdyPanel" style="margin-top:3px;">
                <div class="zdyTool">
                    <div class="zdyBar" style="width:70%;float:left;">
                        <ul class="zdyUL">
                            <li><a id="NF-edit" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改需求记录</a></li>
                            <li><a id="NF-detail" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除需求记录</a></li>
                            <li><a id="NF-detail" onclick="btn_detail()"><i class="fa fa-search-plus"></i>查看需求记录</a></li>
                        </ul>
                    </div>
                    <div class="zdyBar" style="float:right;white-space:nowrap;width:140px;">
                        <div class="btn-group">
                            <a id="NF-add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-eraser"></i>新建需求记录</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="zdyGirdPanel">
                <table id="gridListNeedRecord"></table>
                <div id="gridPagerNeedRecord"></div>
            </div>
        </div>*@
    </div>
</div>